package com.common.library;

import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;

public class App {

    private static App app;
    private Context mContext;
    private Handler mHandler;
    private Thread mMainThread;
    private String mSpName;

    private App() {

    }


    public static App getInstance() {
        if (app == null) {
            synchronized (App.class) {
                if (app == null) {
                    app = new App();
                }
            }
        }
        return app;
    }

    public void init(Context context) {
        init(context, "qiandroidSP");
    }

    public void init(Context context, String spName) {
        this.mContext = context;
        this.mSpName = spName;
        this.mHandler = new Handler();
        this.mMainThread = Thread.currentThread();
    }

    public Context getApplicationContext() {
        if (app == null)
            throw new NullPointerException("App必须初始化");

        if (mContext == null)
            throw new NullPointerException("context不能为空");
        return mContext;
    }

    public String getSpName() {
        if (TextUtils.isEmpty(mSpName)) {
            throw new NullPointerException("SP文件名不能为空");
        }
        return mSpName;
    }

    public Thread getMainThread() {
        return mMainThread;
    }

    public Handler getHandler() {
        return mHandler;
    }

}
